<template>
  <view class="isProceedCodeDialog">
    <view class="dialogContent">
      <!-- 标题 -->
      <view class="header">
        <text>选择货柜</text>
        <u-icon name="close" color="#1c1c1c" size="32rpx" @click="handleClose"></u-icon>
      </view>
      <!-- 列表区域 -->
      <view class="contentWrap">
        <view class="tableWrap">
          <!-- 表头 -->
          <view class="tableHeader">
            <view class="thItem radio">序号</view>
            <view class="thItem title">货柜名称</view>
            <view class="thItem title">负责人</view>
            <view class="thItem code">状态</view>
          </view>
          <!-- 表格内容 -->
          <u-list class="tableBody" @scrolltolower="scrolltolower">
            <view class="trItem" v-for="(item, index) in listData" :key="index">
              <view class="tdItem radio">{{ index + 1 }}</view>
              <view class="tdItem title">{{ item.conName }}</view>
              <view class="tdItem title">{{ item.personCharge }}</view>
              <view class="tdItem code">
                <view class="btn" :class="{ 'active': item.conStatus != 1 }" @click="handleCheck(item, index)">
                  {{ item.conStatus != 1 ? '不可选择' : '选择' }}
                </view>
              </view>
            </view>
          </u-list>
        </view>
      </view>

    </view>
  </view>
</template>

<script>
import { containerList } from "@/common/api/huogui/huogui.js";
export default {
  data() {
    return {
      listData: [],
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        query: {}
      },
      totalPages: 1,
    }
  },
  created() {
    this.getList();
  },
  methods: {

    // 选择货柜
    handleCheck(item, index) {
      // if (item.conStatus) {
      //   return uni.showToast({
      //     title: "该货柜不可以选择",
      //     icon: "none"
      //   });
      // }
      const that = this;
      uni.showModal({
        title: '选择货柜确认',
        content: '确定绑定检修货柜信息？',
        success: function (res) {
          if (res.confirm) {
            that.$emit('handleConfirm', item)
          }
        }
      });
    },
    scrolltolower() {
      if (this.queryParams.pageNum < this.totalPages) {
        this.queryParams.pageNum = this.queryParams.pageNum + 1;
        this.getList();
      }
    },

    getList() {
      containerList(this.queryParams).then((res) => {
        if (res && res.code == 200 && res.data) {
          let list = res.data.rows.map(item => {
            return {
              ...item,
              checked: false
            }
          });
          this.listData = this.listData.concat(list);
          this.totalPages = res.data.totalPages;
        }
      });
    },
    navigateTo(url) {
      uni.navigateTo({
        url
      })
    },

    handleClose() {
      this.$emit('handleClose')
    }
  }
}
</script>

<style lang="scss" scoped>
.isProceedCodeDialog {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 999;
  background: rgba(0, 0, 0, 0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 40rpx;

  .dialogContent {
    position: relative;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    width: 100%;
    padding: 20rpx;
    border-radius: 32rpx;
    border: 3rpx solid #fff;
    background: linear-gradient(180deg, #d2e7ff 0%, #ffffff 19.63%);

    .header {
      width: 100%;
      display: flex;
      align-items: center;
      justify-content: space-between;
      margin-bottom: 10rpx;

      &::before {
        content: '';
        display: block;
        position: absolute;
        right: -30rpx;
        bottom: 0;
        width: 84rpx;
        height: 26rpx;
        background-repeat: no-repeat;
        background-position: center;
        background-size: cover;
      }

      text {
        position: relative;
        z-index: 2;
        color: #1c1c1c;
        font-weight: bold;
        font-size: 30rpx;
      }
    }

    .contentWrap {
      border-radius: 20rpx;
      border: 2rpx solid #d9d9d9;

      .tableWrap {
        .tableHeader {
          display: flex;
          align-items: center;
          background: #F7F8FA;
          border-radius: 20rpx 20rpx 0 0;
          border-bottom: 2rpx solid #d9d9d9;


          .thItem {
            font-size: 28rpx;
            color: #5d94f5;
            text-align: center;
            border-right: 2rpx solid #d9d9d9;
            padding: 28rpx 0;
            position: relative;


            &.radio {
              width: 80rpx;
              min-width: 80rpx;
              max-width: 80rpx;
            }

            &.title {
              flex: 1;
            }

            &.code {
              width: 140rpx;

              &:last-child {
                border-right: none;
              }
            }
          }
        }

        .tableBody {
          min-height: max-content;
          max-height: 438rpx;
          overflow: auto;

          .trItem {
            display: flex;
            border-bottom: 2rpx solid #d9d9d9;
            height: 100%;

            &:last-child {
              // border-bottom: none;
            }

            .tdItem {
              font-size: 24rpx;
              color: #1C1C1C;
              text-align: center;
              border-right: 2rpx solid #d9d9d9;
              padding: 28rpx 10rpx;

              &.radio {
                width: 80rpx;
                min-width: 80rpx;
                max-width: 80rpx;
                display: flex;
                justify-content: center;
                align-items: center;
                padding: 0;

                /deep/uni-radio .uni-radio-input {
                  margin-right: 0;
                }

              }

              &.title {
                flex: 1;
                display: flex;
                align-items: center;
                justify-content: center;
                white-space: normal;
                word-break: break-all;
                word-wrap: break-word;
                line-break: anywhere;
              }

              &.code {
                width: 140rpx;

                &:last-child {
                  border-right: none;
                }

                .btn {
                  font-size: 24rpx;
                  padding: 10rpx;
                  display: flex;
                  justify-content: center;
                  align-items: center;
                  background: #2B7FF3;
                  color: #fff;
                  border-radius: 10rpx;
                }

                .active {
                  background: #999;
                }
              }
            }
          }
        }
      }

    }


  }
}
</style>
